package puzzle.ftest.solver.base;

import org.junit.Assert;

import puzzle.common.data.AbstractBoard;
import puzzle.common.solver.AbstractSolver;
import puzzle.common.solver.SolutionState;
import puzzle.common.solver.SolverAbortingException;
import puzzle.common.view.swing.PuzzleSolverAppMetadata;

public abstract class SolverTestBase<B extends AbstractBoard<B>> {
	protected final PuzzleSolverAppMetadata<B> m_metadata;

	public SolverTestBase(PuzzleSolverAppMetadata<B> metadata) {
		m_metadata = metadata;
	}

	protected final void solve(String name, B b) throws SolverAbortingException {
		AbstractSolver<B, ?, ?> solver = m_metadata.createSolver();
		long st = System.currentTimeMillis();
		SolutionState ss = solver.solveAll(b);
		System.out.println(name + ": " + (System.currentTimeMillis() - st) / 1000.0 + "s");
		Assert.assertEquals(SolutionState.COMPLETE, ss);
	}
}
